<?php 

	define( "USER_NAME", "CCAPLISOADMIN" );
	define( "PASSWORD", "CCAPMcD3RM1T" );

	if( isset( $_POST['submitted'] ) ) {
		
		$userName = $_POST['username'];
		$password = $_POST['password'];
		
		if( empty($userName) OR empty($password) ) {
			$error = "Either your name or password was not entered";
		}
		else {
			if( $userName == USER_NAME && $password == PASSWORD ) {
				session_start();
				$_SESSION['username'] = $userName;
				$_SESSION['password'] = $password;
				$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
				if( ( substr( $url, -1 ) == '/' ) OR substr( $url, -1 ) == '\\' ) {
					$url = substr( $url, 0, -1 );
				}
				$url .= '/messageCue.php';
				header( "Location: $url" );
				exit();
			}
			else {
				$error = "Either your name or password was not correct";
			}
		}
	}
	
	include 'pageParts/header.php';
	echo( '<div id="error">' . $error . '</div>' );
	print <<< END
	<h2>Login</h2>
	<form action="index.php" method="post">
		<p>User Name:<input type="text" name="username" size="20" maxlength="40" /></p>
		<p>Password:<input type="password" name="password" size="20" maxlength="40" /></p>
		<p><input type="submit" name="submit" value="Login" /></p>
		<input type="hidden" name="submitted" value="TRUE" />
	</form>
END;
	include 'pageParts/footer.php';
	
?>